import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../views/Login";
import BlogDetail from "../views/BlogDetail";
import Blogs from "../views/Blogs";
import BlogEdit from "../views/BlogEdit";


Vue.use(VueRouter)

//路由是按照顺序访问的，所以/blog/:blogId 要放在/blog/:blogId/edit前面
const routes = [
  {
    //博客列表
    path: '/',
    name: 'Index',
    //也可以这样写    redirect: {name: "Blogs"}
    component: Blogs,
  },
  {
    //博客列表
    path: '/blogs',
    name: 'Blogs',
    component: Blogs
  },
  {
    //登录页面
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    //增加blog
    path: '/blog/add',
    name: 'BlogAdd',
    meta: {
      requireAuth: true
    },
    component: BlogEdit
  },
  {
    //博客详情页
    path: '/blog/:blogId',
    name: 'BlogDetail',
    component: BlogDetail
  },
  {
    //编辑博客
    //接受前端传递来的参数 blogId
    path: '/blog/:blogId/edit',
    name: 'BlogEdit',
    component: BlogEdit
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
